from product_upload.util.basic.mysql_util import db_get_one


class BasicImage:
    # 字段顺序与数据库字段一致
    fields = ['id', 'status', 'published','basic_id', 'sku', 'class_name','product_type', 'platform', 'title', 'main_image', 'other_image_url1',
              'other_image_url2', 'other_image_url3', 'other_image_url4', 'other_image_url5', 'other_image_url6',
              'other_image_url7', 'other_image_url8', 'other_image_url9', 'other_image_url10', 'other_image_url11',
              'other_image_url12', 'other_image_url13', 'other_image_url14', 'other_image_url15', 'create_time',
              'update_time', 'ocr_result', 'ocr_status', 'remark', 'update_by','image_count']

    def __init__(self, **kwargs):
        self.id = kwargs.get('id', None)
        self.status = kwargs.get('status', None)
        self.published = kwargs.get('published', None)
        self.basic_id = kwargs.get('basic_id', None)
        self.sku = kwargs.get('sku', None)
        self.class_name = kwargs.get('class_name', None)
        self.product_type = kwargs.get('product_type', None)
        self.platform = kwargs.get('platform', None)
        self.title = kwargs.get('title', "")
        self.main_image = kwargs.get('main_image', "")
        self.other_image_url1 = kwargs.get('other_image_url1', "")
        self.other_image_url2 = kwargs.get('other_image_url2', "")
        self.other_image_url3 = kwargs.get('other_image_url3', "")
        self.other_image_url4 = kwargs.get('other_image_url4', "")
        self.other_image_url5 = kwargs.get('other_image_url5', "")
        self.other_image_url6 = kwargs.get('other_image_url6', "")
        self.other_image_url7 = kwargs.get('other_image_url7', "")
        self.other_image_url8 = kwargs.get('other_image_url8', "")
        self.other_image_url9 = kwargs.get('other_image_url9', "")
        self.other_image_url10 = kwargs.get('other_image_url10', "")
        self.other_image_url11 = kwargs.get('other_image_url11', "")
        self.other_image_url12 = kwargs.get('other_image_url12', "")
        self.other_image_url13 = kwargs.get('other_image_url13', "")
        self.other_image_url14 = kwargs.get('other_image_url14', "")
        self.other_image_url15 = kwargs.get('other_image_url15', "")
        self.create_time = kwargs.get('create_time', None)
        self.update_time = kwargs.get('update_time', None)
        self.ocr_result = kwargs.get('ocr_result', None)
        self.ocr_status = kwargs.get('ocr_status', None)
        self.remark = kwargs.get('remark', None)
        self.update_by = kwargs.get('update_by', None)
        self.image_count = kwargs.get('image_count', None)

    @classmethod
    def from_db(cls, field_names, row) -> 'BasicImage':
        if len(field_names) != len(row):
            raise ValueError("bug!---db field len != query field len")
        data_dict = dict(zip(field_names, row))
        return cls(**data_dict)

    def __repr__(self):
        field_info = []
        for field in self.fields:
            value = getattr(self, field)
            field_info.append(f"{field}={repr(value)}")
        return f"BasicImage=[{', '.join(field_info)}]"


if __name__ == '__main__':
    print(db_get_one("basic_image", "id=3", BasicImage))
    pass
